package com.abaaba.project2.service.serviceImpl;

import com.abaaba.project2.bean.System;
import com.abaaba.project2.bean.bo.ConfigWXBO;
import com.abaaba.project2.bean.vo.ConfigeWxVO;
import com.abaaba.project2.mapper.SystemMapper;
import com.abaaba.project2.service.AdminConfigWXService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author Hedgehog
 * @Date 2021/6/6 23:33
 * @Version 1.0
 */
@Service
public class AdminConfigWXServiceImpl implements AdminConfigWXService {

    @Autowired
    SystemMapper systemMapper;

    @Override
    public ConfigeWxVO selectConfigWX() {

        //获取四个pojo
        System systemShare = systemMapper.selectByPrimaryKey(36);
        System systemBrand = systemMapper.selectByPrimaryKey(47);
        System systemTopic = systemMapper.selectByPrimaryKey(48);
        System systemHot = systemMapper.selectByPrimaryKey(41);
        System systemGoods = systemMapper.selectByPrimaryKey(43);
        System systemList = systemMapper.selectByPrimaryKey(45);
        System systemNew = systemMapper.selectByPrimaryKey(34);
        //获取值
        String share = systemShare.getKeyValue();
        String brand = systemBrand.getKeyValue();
        String topic = systemTopic.getKeyValue();
        String hot = systemHot.getKeyValue();
        String goods = systemGoods.getKeyValue();
        String list = systemList.getKeyValue();
        String news = systemNew.getKeyValue();
        //封装
        ConfigeWxVO configeWxVO = new ConfigeWxVO();
        configeWxVO.setCskaoyanmall_wx_index_topic(topic);
        configeWxVO.setCskaoyanmall_wx_catlog_goods(goods);
        configeWxVO.setCskaoyanmall_wx_catlog_list(list);
        configeWxVO.setCskaoyanmall_wx_index_brand(brand);
        configeWxVO.setCskaoyanmall_wx_index_new(news);
        configeWxVO.setCskaoyanmall_wx_index_hot(hot);
        configeWxVO.setCskaoyanmall_wx_share(share);
        return configeWxVO;
    }

    @Override
    public void updateConfigWX(ConfigWXBO configWXBO) {



        System systemShare = new System();
        systemShare.setId(36);
        systemShare.setKeyValue(configWXBO.getCskaoyanmall_wx_share());

        System systemTopic = new System();
        systemTopic.setId(48);
        systemTopic.setKeyValue(configWXBO.getCskaoyanmall_wx_index_topic());

        System systemBrand = new System();
        systemBrand.setId(47);
        systemBrand.setKeyValue(configWXBO.getCskaoyanmall_wx_index_brand());

        System systemHot = new System();
        systemHot.setId(41);
        systemHot.setKeyValue(configWXBO.getCskaoyanmall_wx_index_hot());

        System systemGoods = new System();
        systemGoods.setId(43);
        systemGoods.setKeyValue(configWXBO.getCskaoyanmall_wx_catlog_goods());

        System systemList = new System();
        systemList.setId(45);
        systemList.setKeyValue(configWXBO.getCskaoyanmall_wx_catlog_list());

        System systemNew = new System();
        systemNew.setId(34);
        systemNew.setKeyValue(configWXBO.getCskaoyanmall_wx_index_new());


        systemMapper.updateByPrimaryKeySelective(systemBrand);
        systemMapper.updateByPrimaryKeySelective(systemGoods);
        systemMapper.updateByPrimaryKeySelective(systemHot);
        systemMapper.updateByPrimaryKeySelective(systemList);
        systemMapper.updateByPrimaryKeySelective(systemNew);
        systemMapper.updateByPrimaryKeySelective(systemShare);
        systemMapper.updateByPrimaryKeySelective(systemTopic);
    }


}
